/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.date.DateUtil
 *  cn.hutool.core.util.ObjectUtil
 *  cn.hutool.core.util.StrUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.Button
 *  javafx.scene.control.ComboBox
 *  javafx.scene.control.DatePicker
 *  javafx.scene.control.TextField
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.scene.layout.VBox
 *  javafx.stage.Stage
 *  javafx.util.StringConverter
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.saleReturn;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.SaleScheduleSettingUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.data.KeyValue;
import com.gys.common.util.CacheUtil;
import com.gys.common.util.CommonUtil;
import com.gys.common.util.ConstUtil;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.index.IndexController;
import com.gys.controller.saleReturn.SaleReturnController;
import com.gys.data.example.GetLoginStoreOutData;
import com.gys.data.example.GetUserOutData;
import com.gys.data.saleReturn.GetSaleReturnInData;
import com.gys.view.saleReturn.AddView;
import de.felixroske.jfxsupport.FXMLController;
import java.math.BigDecimal;
import java.net.URL;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.StringConverter;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class AddSaleReturnController
extends BaseController
implements Initializable {
    private final int pageSize = ConstUtil.DEFAULT_PAGESIZE;
    private final int defaultPageCount = ConstUtil.DEFAULT_PAGECOUNT;
    @FXML
    private AnchorPane pane;
    @FXML
    private VBox vBox;
    @FXML
    private Button enterBtn;
    @FXML
    private TextField billNo;
    @FXML
    private TextField time;
    @FXML
    private TextField amount;
    @FXML
    private TextField user;
    @FXML
    private ComboBox<KeyValue> returnEmp;
    @FXML
    private DatePicker date;
    @Autowired
    private SaleReturnController saleReturnController;
    @Autowired
    private IndexController indexController;
    public ObservableList<KeyValue> empOptions;

    public void initialize(URL location, ResourceBundle resources) {
        StringConverter converter = CommonUtil.dataPickerFormat("yyyyMMdd");
        this.date.setConverter(converter);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        List<GetUserOutData> outDataList = new ArrayList();
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("client", ((GetUserOutData)CacheUtil.get("logInUser")).getClient());
        param.put("depId", ((GetLoginStoreOutData)CacheUtil.get("store")).getStoCode());
        HttpJson httpJson = SaleScheduleSettingUtil.queryDocter(param);
        if (!httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
        outDataList = JSON.parseArray((String)httpJson.getMsg(), GetUserOutData.class);
        ArrayList gsegNameOptionList = new ArrayList();
        outDataList.forEach(item -> gsegNameOptionList.add(new KeyValue(item.getUserNam(), item.getUserId())));
        this.empOptions = FXCollections.observableArrayList(gsegNameOptionList);
        this.returnEmp.setItems(this.empOptions);
        CommonUtil.comboxInit(this.returnEmp);
        this.returnEmp.setValue(new KeyValue());
        new Timer().schedule(new TimerTask(){

            @Override
            public void run() {
                AddView view = SpringUtil.getBean(AddView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent event) {
                        if (event.getCode() == KeyCode.ENTER) {
                            AddSaleReturnController.this.saveAdd();
                            return;
                        }
                        if (event.getCode() == KeyCode.ESCAPE) {
                            AddSaleReturnController.this.closeWindows();
                            return;
                        }
                    }
                });
            }
        }, 1000L);
        this.billNo.setText("");
        this.time.setText("");
        this.date.setValue(null);
        this.user.setText("");
        this.amount.setText("");
        this.returnEmp.setValue(null);
    }

    @FXML
    private void saveAdd() {
        Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", null);
        if (StrUtil.isBlank((CharSequence)this.billNo.getText().trim()) || ObjectUtil.isNull(this.date.getValue()) || StrUtil.isBlank((CharSequence)this.time.getText().trim()) || StrUtil.isBlank((CharSequence)this.amount.getText().trim()) || StrUtil.isBlank((CharSequence)this.user.getText().trim()) || ObjectUtil.isNull(this.returnEmp.getValue())) {
            alert.setContentText("\u8bf7\u586b\u5199\u5b8c\u6574\u5185\u5bb9\uff01");
            alert.showAndWait();
            return;
        }
        GetSaleReturnInData inData = new GetSaleReturnInData();
        inData.setGsshBillNo(this.billNo.getText().trim());
        inData.setGsshTime(this.time.getText().trim());
        inData.setGsshDate(DateUtil.format((Date)DateUtil.parse((String)((LocalDate)this.date.getValue()).toString()), (String)"yyyyMMdd"));
        inData.setGsshEmp(this.user.getText().trim());
        inData.setGsshYsAmt(new BigDecimal(this.amount.getText().trim()));
        inData.setGsshEmpReturn(((KeyValue)this.returnEmp.getValue()).getValue());
        this.saleReturnController.add(inData);
        this.pane.getScene().getWindow().hide();
    }

    @FXML
    private void closeWindows() {
        this.pane.getScene().getWindow().hide();
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public int getDefaultPageCount() {
        return this.defaultPageCount;
    }

    public AnchorPane getPane() {
        return this.pane;
    }

    public VBox getVBox() {
        return this.vBox;
    }

    public Button getEnterBtn() {
        return this.enterBtn;
    }

    public TextField getBillNo() {
        return this.billNo;
    }

    public TextField getTime() {
        return this.time;
    }

    public TextField getAmount() {
        return this.amount;
    }

    public TextField getUser() {
        return this.user;
    }

    public ComboBox<KeyValue> getReturnEmp() {
        return this.returnEmp;
    }

    public DatePicker getDate() {
        return this.date;
    }

    public SaleReturnController getSaleReturnController() {
        return this.saleReturnController;
    }

    public IndexController getIndexController() {
        return this.indexController;
    }

    public ObservableList<KeyValue> getEmpOptions() {
        return this.empOptions;
    }

    public void setPane(AnchorPane pane) {
        this.pane = pane;
    }

    public void setVBox(VBox vBox) {
        this.vBox = vBox;
    }

    public void setEnterBtn(Button enterBtn) {
        this.enterBtn = enterBtn;
    }

    public void setBillNo(TextField billNo) {
        this.billNo = billNo;
    }

    public void setTime(TextField time) {
        this.time = time;
    }

    public void setAmount(TextField amount) {
        this.amount = amount;
    }

    public void setUser(TextField user) {
        this.user = user;
    }

    public void setReturnEmp(ComboBox<KeyValue> returnEmp) {
        this.returnEmp = returnEmp;
    }

    public void setDate(DatePicker date) {
        this.date = date;
    }

    public void setSaleReturnController(SaleReturnController saleReturnController) {
        this.saleReturnController = saleReturnController;
    }

    public void setIndexController(IndexController indexController) {
        this.indexController = indexController;
    }

    public void setEmpOptions(ObservableList<KeyValue> empOptions) {
        this.empOptions = empOptions;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof AddSaleReturnController)) {
            return false;
        }
        AddSaleReturnController other = (AddSaleReturnController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        if (this.getPageSize() != other.getPageSize()) {
            return false;
        }
        if (this.getDefaultPageCount() != other.getDefaultPageCount()) {
            return false;
        }
        AnchorPane this$pane = this.getPane();
        AnchorPane other$pane = other.getPane();
        if (this$pane == null ? other$pane != null : !this$pane.equals(other$pane)) {
            return false;
        }
        VBox this$vBox = this.getVBox();
        VBox other$vBox = other.getVBox();
        if (this$vBox == null ? other$vBox != null : !this$vBox.equals(other$vBox)) {
            return false;
        }
        Button this$enterBtn = this.getEnterBtn();
        Button other$enterBtn = other.getEnterBtn();
        if (this$enterBtn == null ? other$enterBtn != null : !this$enterBtn.equals(other$enterBtn)) {
            return false;
        }
        TextField this$billNo = this.getBillNo();
        TextField other$billNo = other.getBillNo();
        if (this$billNo == null ? other$billNo != null : !this$billNo.equals(other$billNo)) {
            return false;
        }
        TextField this$time = this.getTime();
        TextField other$time = other.getTime();
        if (this$time == null ? other$time != null : !this$time.equals(other$time)) {
            return false;
        }
        TextField this$amount = this.getAmount();
        TextField other$amount = other.getAmount();
        if (this$amount == null ? other$amount != null : !this$amount.equals(other$amount)) {
            return false;
        }
        TextField this$user = this.getUser();
        TextField other$user = other.getUser();
        if (this$user == null ? other$user != null : !this$user.equals(other$user)) {
            return false;
        }
        ComboBox<KeyValue> this$returnEmp = this.getReturnEmp();
        ComboBox<KeyValue> other$returnEmp = other.getReturnEmp();
        if (this$returnEmp == null ? other$returnEmp != null : !this$returnEmp.equals(other$returnEmp)) {
            return false;
        }
        DatePicker this$date = this.getDate();
        DatePicker other$date = other.getDate();
        if (this$date == null ? other$date != null : !this$date.equals(other$date)) {
            return false;
        }
        SaleReturnController this$saleReturnController = this.getSaleReturnController();
        SaleReturnController other$saleReturnController = other.getSaleReturnController();
        if (this$saleReturnController == null ? other$saleReturnController != null : !(this$saleReturnController).equals(other$saleReturnController)) {
            return false;
        }
        IndexController this$indexController = this.getIndexController();
        IndexController other$indexController = other.getIndexController();
        if (this$indexController == null ? other$indexController != null : !(this$indexController).equals(other$indexController)) {
            return false;
        }
        ObservableList<KeyValue> this$empOptions = this.getEmpOptions();
        ObservableList<KeyValue> other$empOptions = other.getEmpOptions();
        return !(this$empOptions == null ? other$empOptions != null : !this$empOptions.equals(other$empOptions));
    }

    protected boolean canEqual(Object other) {
        return other instanceof AddSaleReturnController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        result = result * 59 + this.getPageSize();
        result = result * 59 + this.getDefaultPageCount();
        AnchorPane $pane = this.getPane();
        result = result * 59 + ($pane == null ? 43 : $pane.hashCode());
        VBox $vBox = this.getVBox();
        result = result * 59 + ($vBox == null ? 43 : $vBox.hashCode());
        Button $enterBtn = this.getEnterBtn();
        result = result * 59 + ($enterBtn == null ? 43 : $enterBtn.hashCode());
        TextField $billNo = this.getBillNo();
        result = result * 59 + ($billNo == null ? 43 : $billNo.hashCode());
        TextField $time = this.getTime();
        result = result * 59 + ($time == null ? 43 : $time.hashCode());
        TextField $amount = this.getAmount();
        result = result * 59 + ($amount == null ? 43 : $amount.hashCode());
        TextField $user = this.getUser();
        result = result * 59 + ($user == null ? 43 : $user.hashCode());
        ComboBox<KeyValue> $returnEmp = this.getReturnEmp();
        result = result * 59 + ($returnEmp == null ? 43 : $returnEmp.hashCode());
        DatePicker $date = this.getDate();
        result = result * 59 + ($date == null ? 43 : $date.hashCode());
        SaleReturnController $saleReturnController = this.getSaleReturnController();
        result = result * 59 + ($saleReturnController == null ? 43 : ($saleReturnController).hashCode());
        IndexController $indexController = this.getIndexController();
        result = result * 59 + ($indexController == null ? 43 : ($indexController).hashCode());
        ObservableList<KeyValue> $empOptions = this.getEmpOptions();
        result = result * 59 + ($empOptions == null ? 43 : $empOptions.hashCode());
        return result;
    }

    public String toString() {
        return "AddSaleReturnController(pageSize=" + this.getPageSize() + ", defaultPageCount=" + this.getDefaultPageCount() + ", pane=" + this.getPane() + ", vBox=" + this.getVBox() + ", enterBtn=" + this.getEnterBtn() + ", billNo=" + this.getBillNo() + ", time=" + this.getTime() + ", amount=" + this.getAmount() + ", user=" + this.getUser() + ", returnEmp=" + this.getReturnEmp() + ", date=" + this.getDate() + ", saleReturnController=" + this.getSaleReturnController() + ", indexController=" + this.getIndexController() + ", empOptions=" + this.getEmpOptions() + ")";
    }
}

